package com.zhangtai.modules.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhangtai.modules.dto.DimissionUpcomingDto;
import com.zhangtai.modules.entity.employee.DimissionUpcomingEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 离职审计待办
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-09-03 11:14:51
 */
@Mapper
public interface DimissionUpcomingDao extends BaseMapper<DimissionUpcomingEntity> {


    @Select(
            "<script>" +
                    "Select upcoming.*,audit.`code`,audit.`name`,\n" +
                    "\taudit.oid,\n" +
                    "\taudit.jobname,\n" +
                    "\taudit.job_level_id,\n" +
                    "\taudit.job_level,\n" +
                    "\taudit.job_level_type,\n" +
                    "\taudit.orgname,\n" +
                    "\taudit.unitname,\n" +
                    "\taudit.job_system,\n" +
                    "\taudit.line,\n" +
                    "\taudit.hiredate,\n" +
                    "\taudit.dimission_time,\n" +
                    "\taudit.working_years    from tb_dimission_upcoming upcoming  " +
                    "left join tb_dimission_audit audit  on audit.id = upcoming.audit_id  " +
                    "<where>  upcoming.is_delete = 0 " +

                    "<if test='orgIds!=null and orgIds.size>0'> and audit.unit_id in " +
                    " <foreach item=\"orgId\" index=\"index\" collection=\"orgIds\" open=\"(\" separator=\",\" close=\")\">#{orgId}</foreach>" +
                    "</if>"+
                    "<if test='orgIds==null or orgIds.size==0'> and audit.unit_id = null </if>" +

                    "<if test='name!=null'> and audit.name like '%${name}%' </if>" +
                    "<if test='code!=null'> and audit.code like '%${code}%' </if>" +
                    "<if test='hiredateStart!=null'> and audit.hiredate >= #{hiredateStart} </if>" +
                    "<if test='hiredateEnd!=null'> and audit.hiredate >= #{hiredateEnd} </if>" +
                    "<if test='jobLevelId!=null'> and audit.job_level_id = #{jobLevelId} </if>" +
                    "<if test='lineId!=null'> and audit.line_id = #{lineId} </if>" +
                    "<if test='jobSystemId!=null'> and audit.job_system_id = #{jobSystemId} </if>" +
                    "<if test='status!=null'> and upcoming.status = #{status} </if>" +
                    "</where>  order by upcoming.create_time desc" +
                    "</script>"
    )
    List<DimissionUpcomingDto> getDimissionUpcomingList(
            @Param("orgIds") List<Long> orgIds,
            @Param(value = "name") String name,
            @Param(value = "code") String code,
            @Param(value = "hiredateStart") String hiredateStart,
            @Param(value = "hiredateEnd") String hiredateEnd,
            @Param(value = "jobLevelId") Long jobLevelId, //职级id
            @Param(value = "lineId") Long lineId, //专业职级id
            @Param(value = "jobSystemId") Long jobSystemId, //专业职级id
            @Param(value = "status") Integer status, //审批状态
            Page<DimissionUpcomingDto> page
    );

}
